function Timeline(id, parentDivId){
	this.count = 0;
	this.id = id;
	this.timelineIds = [];
	this.timelineHash = {};
	this.timeline = '<div id="' + id + '"></div>';
	this._initilaize(parentDivId);
	this.minId = 0;
	this.minFlag = true;
}

Timeline.prototype = {
	_initilaize : function(parentDivId){
		$('#' + parentDivId).append(this.timeline);
	},
	isContain : function(id){
		for(var i in this.timelineIds){
			if(this.timelineIds[i] == id){
				return true;
			}
		}
		return false;
	},
	get : function(id){
		var data = null;
		for(var i in this.timelineIds){
			if(this.timelineIds[i].id == id){
				data = this.timelineIds[index];
				break;
			}
		}
		return data;
	},
	remove : function(id){
		var data = null;
		for(var i in this.timelineIds){
			if(this.timelineIds[i].id == id){
				data = this.timelineIds[i];
				$("div .tweet_unit[timeline.id=" + data + "]").remove();
				break;
			}
		}
		return data;
	},
	prepend : function(tweet){
		if(tweet.retweeted_status != undefined){
			var unit = this._createReTweetUnit(tweet.retweeted_status, tweet);
			this.timelineIds.unshift(tweet.retweeted_status.id_str);
		}else{
			var unit = this._createTweetUnit(tweet);
			this.timelineIds.unshift(tweet.id_str);
		}
		$("#" + this.id).prepend(unit);
		this.count++;
	},
	append : function(tweet){
		if(tweet.retweeted_status != undefined){
			var unit = this._createReTweetUnit(tweet.retweeted_status, tweet);
			this.timelineIds.push(tweet.retweeted_status.id_str);
		}else{
			var unit = this._createTweetUnit(tweet);
			this.timelineIds.push(tweet.id_str);
		}
		$("#" + this.id).append(unit);
		//this.timelineData.push(tweet);
		this.count++;
	},
	appendForUniv : function(tweet){
		if(tweet.retweeted_status != undefined){
			var unit = this._createReTweetUnit(tweet.retweeted_status, tweet);
			this.timelineIds.push(tweet.retweeted_status.id_str);
		}else{
			var unit = this._createTweetUnitForUniv(tweet);
			this.timelineIds.push(tweet.Status.id);
		}
		if(this.minFlag){
			this.minId = tweet.Status.id;
			this.minFlag = false;
		}
		if(this.minId > tweet.Status.id){
			this.minId = tweet.Status.id;
		}
		$("#" + this.id).append(unit);
		//this.timelineData.push(tweet);
		this.count++;
	},
	appendNextTweet : function(){
		var unit = '';
		unit += '<div class="tweet_unit" data-theme="a" data-content-theme="a">';
		unit += '次を見る';
		unit += '</div>';
		$("#" + this.id).append(unit);
	},
	_createReTweetUnit : function(rt, tweet){
		//p(rt.id_str);
		var unit = '';
		unit += '<div timeline-id="' + rt.id_str + '" class="tweet_unit" data-theme="a" data-content-theme="a">';
		unit += '<img user-id="' + rt.user.id +  '" src="' + rt.user.profile_image_url + '">';
			unit += '<div class="right_tweet_area">';
				unit += '<div class="username">' + rt.user.screen_name + '</div>';
				unit += '<div class="user_real_name">' + rt.user.name + '</div>';
				unit += '<div class="tweet">' + rt.text + '</div>';
				unit += '<div class="buttom_line">';
					unit += '<div class="address">' + rt.source + '</div>';
				if(false){
					unit += rt.favorited == false ? '<a href="#" class="fav">お気に入りへ追加</a>' : '<a href="#" class="unfav">お気に入りから削除</a>';
					unit += gUser.rtIds[rt.id_str] == undefined ? '<a href="#" class="rt">リツイート</a>' : '<a href="#" class="unrt">リツイートの解除</a>';
				}
					unit += '<div class="created_at">' + date(rt.created_at) + '</div>';
				unit += '</div>';
				unit += '<div style="clear:both;"></div>';
			unit += '</div>';
		unit += '</div>';
		return unit;
	},
	_createTweetUnit : function(tweet){
		var unit = '';
		if( tweet.user.id == gUser.User.id ){
			unit += '<div timeline-id="' + tweet.id_str + '" class="tweet_unit tweet_unit_myself" data-theme="a" data-content-theme="a">';					
		}
		else if(gUser.User.id == tweet.in_reply_to_user_id_str){
			unit += '<div timeline-id="' + tweet.id_str + '" class="tweet_unit tweet_unit_myreply" data-theme="a" data-content-theme="a">';								
		}
		else{
			unit += '<div timeline-id="' + tweet.id_str + '" class="tweet_unit" data-theme="a" data-content-theme="a">';					
		}
		unit += '<img user-id="' + tweet.user.id +  '" src="' + tweet.user.profile_image_url + '">';
			unit += '<div class="right_tweet_area">';
				unit += '<div class="username">' + tweet.user.screen_name + '</div>';
				unit += '<div class="user_real_name">' + tweet.user.name + '</div>';
				unit += '<div class="tweet">' + replaceLink(tweet.text) + '</div>';
				unit += '<div class="buttom_line">';
					unit += '<div class="address">' + tweet.source + '</div>';
				if(false && gUser.User.id != tweet.user.id){
					unit += tweet.favorited == false ? '<a href="#" class="fav">お気に入りへ追加</a>' : '<a href="#" class="unfav">お気に入りから削除</a>';
					unit += gUser.rtIds[tweet.id_str] == undefined ? '<a href="#" class="rt">リツイート</a>' : '<a href="#" class="unrt">リツイートの解除</a>';
				}
					unit += '<div class="created_at">' + date(tweet.created_at) + '</div>';
				unit += '</div>';
				unit += '<div style="clear:both;"></div>';
			unit += '</div>';
		unit += '</div>';
		return unit;
	},
	_createTweetUnitForUniv : function(tweet){
		var unit = '';
		unit += '<div timeline-id="' + tweet.Status.id + '" class="tweet_unit" data-theme="a" data-content-theme="a">';
		unit += '<img user-id="' + tweet.TwitterUser.id +  '" src="' + tweet.TwitterUser.profile_image_url + '">';
			unit += '<div class="right_tweet_area">';
				unit += '<div class="username">' + tweet.TwitterUser.screen_name + '</div>';
				unit += '<div class="user_real_name">' + tweet.TwitterUser.name + '</div>';
				unit += '<div class="tweet">' + replaceLink(tweet.Status.text) + '</div>';
				unit += '<div class="buttom_line">';
					if(tweet.Status.source != ''){
						unit += '<div class="address">' + tweet.Status.source + '</div>';
					}
					if(false && gUser.User.id != tweet.user.id){
						unit += tweet.favorited == false ? '<a href="#" class="fav">お気に入りへ追加</a>' : '<a href="#" class="unfav">お気に入りから削除</a>';
						unit += gUser.rtIds[tweet.id_str] == undefined ? '<a href="#" class="rt">リツイート</a>' : '<a href="#" class="unrt">リツイートの解除</a>';
					}
					if(tweet.Status.created_at != ''){
						unit += '<div class="created_at">' + date(tweet.Status.created_at) + '</div>';
					}
				unit += '</div>';
				unit += '<div style="clear:both;"></div>';
			unit += '</div>';
		unit += '</div>';
		return unit;
	}
}